#
# Copyright © 2021 深圳百问网科技有限公司 All Rights Reserved.
# 视频在线学习：https://www.100ask.net
# 硬件购买地址：https://shop502068889.taobao.com
#
# SPDX-License-Identifier: BSD-3-Clause
#

"""
接线
    CS     ---   5
    RESET  ---   0
    DC     ---   2
    MOSI   ---   23
    CLK    ---   18
    BL     ---   -1
    MISO   ---   19
"""

from machine import Pin, SPI
from sys import implementation
from os import uname
import utime

import ili9341
from ili9341 import Display
from xglcd_font import XglcdFont

print(implementation.name)
print(uname()[3])
print(uname()[4])

print(SPI(1))
print(SPI(2))

TFT_CS_PIN = const(5)
TFT_RST_PIN = const(0)
TFT_DC_PIN = const(2)
"""
hspi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
display = Display(hspi, dc=Pin(TFT_DC_PIN), cs=Pin(TFT_CS_PIN), rst=Pin(TFT_RST_PIN))
"""
vspiTFT = SPI(2, baudrate=80000000, polarity=0, phase=0, bits=8, firstbit=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
display = Display(vspiTFT, dc=Pin(TFT_DC_PIN), cs=Pin(TFT_CS_PIN), rst=Pin(TFT_RST_PIN))

print('Loading fonts...')
print('Loading unispace')
unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24)

display.draw_text(0, 0, ili9341.__name__, unispace,
                  ili9341.color565(0, 0, 200))
display.draw_text(0, 25, ili9341.implementation.name, unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 50, str(ili9341.implementation.version), unispace,
                  ili9341.color565(200, 200, 200))

display.draw_text(0, 100, "www.100ask.net", unispace,
                  ili9341.color565(255, 128, 0))
display.draw_text(0, 125, "www.open314.com", unispace,
                  ili9341.color565(255, 128, 0))

display.draw_text(0, 175, "ABCDEFGHIJKLMNOPQRS", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 200, "TUVWXYZ", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 225, "abcdefghijklmnopqrs", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 250, "tuvwxyz", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 275, "01234567890", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 300, "~!@#$%^&*()_+`-={}[]", unispace,
                  ili9341.color565(200, 200, 200))
display.draw_text(0, 325, "\|;:'<>,.?/", unispace,
                  ili9341.color565(200, 200, 200))
    
for i in range(320):
    display.scroll(i)
    utime.sleep(0.02)
    
for i in range(320, 0, -1):
    display.scroll(i)
    utime.sleep(0.02)

utime.sleep(0.5)
# Display inversion on
display.write_cmd(display.INVON)
utime.sleep(2)
# Display inversion off
display.write_cmd(display.INVOFF)

while True:
    pass

print("- bye -")


